package com.ljy.my_study.java.thread.executor;

import com.ljy.my_study.java.thread.ThreadLocalUtil;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author lijunying
 * @date 2021/5/14 17:35
 */
public class ExecutorTestMain {

    public static void main(String[] args) throws InterruptedException {
        test1();
    }

    public static void test1() throws InterruptedException {
//        Thread.currentThread().setDaemon(true);
        ScheduledExecutorService executor=new ScheduledThreadPoolExecutor(100,
                new BasicThreadFactory.Builder().namingPattern("test-%d").daemon(true).build());

//        executor.schedule(()->
//            System.out.println(Thread.currentThread().getName()+" 执行任务。")
//        ,2,TimeUnit.SECONDS);

        Object object=new Object();
        ReentrantLock lock=new ReentrantLock();
        Condition condition=lock.newCondition();
//        executor.submit(()->{
//            try{
////                lock.lock();
//                try {
//                    condition.await(9,TimeUnit.SECONDS);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                System.out.println(Thread.currentThread().getName()+" 执行任务。");
//            }finally {
////                lock.unlock();
//            }
//        });

        try {
            condition.await(9,TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+" 执行任务。");

//        executor.shutdown();

        Thread.sleep(10000L);
    }
}
